package com.vf.admin.common.freemarker;

import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;

@Component
public class CustomFreeMarkerConfigurer  implements ApplicationContextAware {

    @Autowired
    Configuration configuration;

    @Autowired
    MapStringString mapStringString;

    @Autowired
    MapIntString mapIntString;

    @Autowired
    HtmlGuolv htmlGuolv;


    @PostConstruct //在项目启动时执行方法
    public void setSharedVariable() throws IOException, TemplateException {
        // 将标签perm注册到配置文件
        configuration.setSharedVariable("mapStringString", mapStringString);
        configuration.setSharedVariable("mapIntString", mapIntString);
        configuration.setSharedVariable("htmlGuolv", htmlGuolv);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

    }
}
